package io.renren.modules.bs.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.bs.entity.BsExtractRecordEntity;
import io.renren.modules.bs.vo.ExportExtraRecordExcelVo;
import io.renren.modules.bs.vo.IndexVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-15 23:03:14
 */
@Mapper
public interface BsExtractRecordDao extends BaseMapper<BsExtractRecordEntity> {

    @Select("select hospital.hospital_id,hospital.hospital_name,count(1) extra_num\n" +
            "FROM (SELECT  extra.extract_record_id,extra.hospital_id,count(1) from\n" +
            "(SELECT depart.hospital_id,record.extract_record_id FROM bs_extract_record record\n" +
            "LEFT JOIN bs_extract_record_detail detail on record.extract_record_id = detail.record_id\n" +
            "LEFT JOIN bs_department depart on detail.department_id = depart.department_id) extra \n" +
            "GROUP BY extra.extract_record_id,extra.hospital_id) extra1 \n" +
            "LEFT JOIN bs_hospital hospital on extra1.hospital_id = hospital.hospital_id\n" +
            "GROUP BY  extra1.hospital_id")
    List<IndexVo> getExtraNum();

//    @Select("SELECT hospital.hospital_name,depart.department_name,bdp.*,pat.patient_name,pat.gender FROM bs_extract_record record\n" +
//            "LEFT JOIN bs_extract_record_detail detail on record.extract_record_id = detail.record_id\n" +
//            "LEFT JOIN bs_extract_detail_patient dp on detail.extract_record_detail = dp.detail_id\n" +
//            "LEFT JOIN bs_department depart on detail.department_id = depart.department_id\n" +
//            "LEFT JOIN bs_hospital hospital on depart.hospital_id = hospital.hospital_id\n" +
//            "LEFT JOIN bs_department_patient  bdp on dp.department_patient_id = bdp.department_patient_id\n" +
//            "LEFT JOIN bs_patient pat on bdp.patient_id = pat.patient_id\n" +
//            "WHERE record.extract_record_id = #{extractRecordId}")
    @Select("SELECT hospital.hospital_name,depart.department_name,detail.extract_num,detail.is_done,dp.department_patient_id,dpa.hospitalization_date,detail.extract_record_detail,pat.patient_name,pat.gender,pat.id_number FROM bs_extract_record record\n" +
            "            LEFT JOIN bs_extract_record_detail detail on record.extract_record_id = detail.record_id\n" +
            "            LEFT JOIN bs_extract_detail_patient dp on detail.extract_record_detail = dp.detail_id\n" +
            "            LEFT JOIN bs_department_patient dpa on dp.department_patient_id = dpa.department_patient_id\n" +
            "            LEFT JOIN bs_patient pat on dpa.patient_id = pat.patient_id\n" +
            "            LEFT JOIN bs_department depart on detail.department_id = depart.department_id\n" +
            "            LEFT JOIN bs_hospital hospital on depart.hospital_id = hospital.hospital_id\n" +
            "WHERE record.extract_record_id = #{extractRecordId} ")
    List<ExportExtraRecordExcelVo> getExportList(Long extractRecordId);
}
